package org.linlinjava.litemall.brand.web;



import org.linlinjava.litemall.brand.annotation.LoginUser;
import org.linlinjava.litemall.brand.service.BrandFigureService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallBrandAppend;
import org.linlinjava.litemall.db.service.LitemallServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户 人物
 */
@RestController
@RequestMapping("/brand/figure")
@Validated
public class BrandFigureController{
    @Autowired
    private BrandFigureService brandFigureService;
    @Autowired
    private LitemallServiceService serviceService;

    @GetMapping("/list")
    public Object list(@LoginUser Integer id){
        Integer brandId = serviceService.getBelong(id);
        List<LitemallBrandAppend> litemallBrandAppends = brandFigureService.findByBrandId(brandId);
        return ResponseUtil.ok(litemallBrandAppends);
    }
    @PostMapping("/add")
    public Object add(@RequestBody LitemallBrandAppend litemallBrandAppend, @LoginUser Integer userId){
        Integer brandId = serviceService.getBelong(userId);
        litemallBrandAppend.setBrandId(brandId);
        brandFigureService.add(litemallBrandAppend);
        return ResponseUtil.ok(litemallBrandAppend);
    }
    @PostMapping("/update")
    public Object update(@RequestBody LitemallBrandAppend litemallBrandAppend){
        brandFigureService.update(litemallBrandAppend);
        return ResponseUtil.ok(litemallBrandAppend);
    }
    @GetMapping("/delete")
    public Object delete(Integer id){
        brandFigureService.delete(id);
        return ResponseUtil.ok();
    }
    @GetMapping("/listPic")
    public Object listPic(@LoginUser Integer id){
        Integer brandId = serviceService.getBelong(id);
        List<LitemallBrandAppend> litemallBrandAppends = brandFigureService.findByBrandIdPic(brandId);
        return ResponseUtil.ok(litemallBrandAppends);
    }
    @PostMapping("/addPic")
    public Object addPic(@RequestBody LitemallBrandAppend litemallBrandAppend, @LoginUser Integer userId){
        Integer brandId = serviceService.getBelong(userId);
        litemallBrandAppend.setBrandId(brandId);
        brandFigureService.addPic(litemallBrandAppend);
        return ResponseUtil.ok(litemallBrandAppend);
    }
    @PostMapping("updatePic")
    public Object updatePic(@RequestBody LitemallBrandAppend litemallBrandAppend){
        brandFigureService.updatePic(litemallBrandAppend);
        return ResponseUtil.ok(litemallBrandAppend);
    }
    @GetMapping("/deletePic")
    public Object deletePic(Integer id){
        brandFigureService.deletePic(id);
        return ResponseUtil.ok();
    }
}
